
// 设备唤醒
device.wakeUp();
openWechat();
function openWechat(){
    // 打开微信
    launchApp("微信");
    sleep(5000);

    // 店家中油好客
    click("中油好客e站");
    sleep(2000);

    // var youka = className("android.widget.TextView").text("我的油卡").findOne().parent().parent();
    // log(youka);
    // youka.click();
    click("我的油卡");
    sleep(1000);

    // var bindingCard = className("android.widget.TextView").text("绑卡/充值").findOne();
    // log(bindingCard);
    // bindingCard.click();
    click("绑卡/充值");
    sleep(3000);

    // var vConsole =idContains("vconsole").findOne();
    var vConsole = bounds(771, 1672, 1050, 1768).clickable();
    // log(vConsole);
    vConsole.click();
    sleep(1000);

    var ok = className("android.widget.Button").text("OK").findOne();
    // log(ok);
    ok.click();
    sleep(1000);

    var storage = className("android.view.View").text("Storage").findOne();
    // id("__vc_tab_storage").findOne();
    // log(storage);
    storage.click();
    sleep(1000);

    // text = RedisSessionCookiesId
    var redisSessionCookiesId = className("android.view.View").text("RedisSessionCookiesId").findOne();
    // log(redisSessionCookiesId);
    // log(redisSessionCookiesId.parent());
    // log(redisSessionCookiesId.parent().child(1));
    var cookiesValue = redisSessionCookiesId.parent().child(1).text();
    // log(cookiesValue);
    var res = putSystemCode(cookiesValue);
    if (res.statusCode == 200){
        quitApp('微信');
    }
}

/**
 * 修改系统cookie
 * @param {cookie参数} cookiesValue 
 */
function putSystemCode(cookiesValue) {
    var params = {
        'id': 1,
        'codeMsg': "微信登录中石油cookie", 
        'codeName': "WC_COOKIE",
        'codeValue': "RedisSessionCookiesId="+cookiesValue 
    }
    var url = "http://120.27.2.47:8090/extral/putExtralSystemCode"
    var res = http.request(url, {
        method: "PUT",
        contentType: "application/json",
        body: JSON.stringify(params)
    })
    log(res.statusCode);
    log(res.body.string());
    return res;
}
/**
 * 关闭应用进程
 * @param {应用名称} name 
 */
function quitApp(name){
    // 点击查看进程
    // click(800,1840);
    // 开启任务栏
    recents();
    sleep(1000);
    // 找到微信
    var apps = className("android.widget.ImageView").desc("移除"+name+"。").findOne();
    // log(apps);
    apps.click();
    sleep(1000);
    home();
}